@ECHO OFF
REM Copyright 2008-*, Micheal Espinola Jr aka ME2 (michealespinola@gmail.com)
REM This script is free to USE & MODIFY or to REDISTRIBUTE in its ORIGINAL FORM,
REM as long as this REM'd passage is always included.

SETLOCAL
SET SCRIPTVER=2.0
SET SCRIPT_NAME=[DUF] Delete Unnecessary Files %SCRIPTVER%
SET    DUF_DAYS=30
IF NOT EXIST .\working MD .\working
IF EXIST .\working\DUF*.txt DEL .\working\DUF*.txt>NUL
IF /I "%1" EQU "quick" (
  SET DUF_START=/MIN
) ELSE (
  SET DUF_START=/WAIT
)
IF /I "%1" EQU "show" (
  SET DUF_START=
  SET DUF_ComSpec=/K
) ELSE (
  SET DUF_ComSpec=/C
)

:TASKS
REM  SCRIPT FUNCTION                   LOG  OBJECT                                       TASK DESCRIPTION
REM  ================================  ===  =====================================        ====================
CALL :DISPLAY_HEADER
CALL :SERVICES STOP
CALL :APPLICATIONS STOP
REM  :CLEAR_DIRECTORY                  "1"  "%windir%\$hf_mig$"                          "Clearing old Windows Hotfix cached ($hf_mig$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$NtServicePackUninstall*$"         "Deleting old Windows Service Pack uninstall ($NtServicePackUninstall*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$NTUpdate*$"                       "Deleting old Windows Update Rollup uninstall ($NTUpdate*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$NTUninstall*$"                    "Deleting old Windows Hotfix uninstall ($NTUninstall*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$SQLUninstall*$"                   "Deleting old SQL Hotfix uninstall ($SQLUninstall*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$ExchUninstall*$"                  "Deleting old Exchange Hotfix uninstall ($ExchUninstall*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%windir%\$MSI*$"                            "Deleting old MSI installer upgrade uninstall ($MSI*$) dirs"
REM  :DELETE_WILDCARD_DIRECTORY        "2"  "%SystemDrive%\*.tmp"                        "Deleting Temporary (*.tmp) dirs"
REM  :DELETE_DIRECTORY                 "1"  "%windir%.old"                               "Deleting old upgraded (Windows.old) dir"
REM  :DELETE_DIRECTORY                 "1"  "%windir%\ie7"                               "Deleting (ie7) uninstall dir"
REM  :DELETE_DIRECTORY                 "1"  "%windir%\ie7updates"                        "Deleting (ie7updates) uninstall dir"
REM  :DELETE_DIRECTORY                 "1"  "%SystemDrive%\Config.Msi"                   "Deleting Office uninstall (Config.Msi) dir"
REM  :DELETE_DIRECTORY                 "1"  "%SystemDrive%\I386"                         "Deleting (I386) dir"
REM  :DELETE_DIRECTORY                 "1"  "%SystemDrive%\MSOCache"                     "Deleting Microsoft Office cache (MSOCache) files"
REM  :CLEAR_DIRECTORY                  "1"  "%SystemDrive%\Temp"                         "Clearing (Temp) dirs"
REM  :CLEAR_DIRECTORY                  "1"  "%SystemDrive%\Temporary Internet Files"     "Clearing (Temporary Internet Files) dirs"
REM  :CLEAR_DIRECTORY                  "1"  "%windir%\.jagex_cache_32"                   "Clearing Java game cache (.jagex_cache_32) dir"
REM  :CLEAR_DIRECTORY                  "1"  "%windir%\Downloaded Installations"          "Clearing (Downloaded Installations) temp dir"
REM  :CLEAR_DIRECTORY                  "1"  "%windir%\Downloaded Program Files"          "Clearing (Downloaded Program Files) installed IE Controls dir"
REM  :CLEAR_DIRECTORY                  "0"  "%windir%\SoftwareDistribution"              "Clearing Windows Update (SoftwareDistribution) temp dir"
CALL :CLEAR_DIRECTORY                  "1"  "%SystemDrive%\Recycled"                     "Clearing (Recycled) dir"
CALL :CLEAR_DIRECTORY                  "1"  "%SystemDrive%\RECYCLER"                     "Clearing (Recycler) dir"
CALL :DELETE_FILES                     "1"  "%windir%\WinSxS\InstallTemp"                "Clearing Side-by-side (WinSxS) Assemblies (InstallTemp) temp dir"
CALL :DELETE_FILES                     "1"  "%SystemDrive%\*.dmp"                        "Deleting crash debug (*.dmp) files"
CALL :DELETE_FILES                     "1"  "%SystemDrive%\*.log"                        "Deleting log (*.log) files"
CALL :DELETE_FILES                     "1"  "%SystemDrive%\*.tmp"                        "Deleting temporary (*.tmp) files"
CALL :DELETE_FILES                     "1"  "%SystemDrive%\~$*.*"                        "Deleting Microsoft Office temporary (~$*.*) files"
CALL  :CLEANMGR
REM  :SERVICES START
CALL :DISPLAY_FOOTER
GOTO :END

:CLEANMGR
CALL :LOG "1" "Performing Disk Cleanup:"
CALL :BUILD_CLEANMGR_REG_FILE
CALL :START                            "2"  "" "REGEDIT /S .\working\DUF_REG.TXT"        "Importing Disk Cleanup settings (1972)"
CALL :START                            "2"  "" "CLEANMGR.EXE /sagerun:1972"              "Running: cleanmgr.exe /sagerun:1972"
GOTO :EOF

:BUILD_CLEANMGR_REG_FILE
ECHO Windows Registry Editor Version 5.00>                                                                                            .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Compress old files]>>                       .\working\DUF_REG.TXT
ECHO [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Office Setup Files]>>                       .\working\DUF_REG.TXT
ECHO [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files]>>                         .\working\DUF_REG.TXT
ECHO [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System Restore]>>                           .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]>>                                           .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders]>>                 .\working\DUF_REG.TXT
ECHO @="{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Display"="Temporary Setup Files">>                                                                                              .\working\DUF_REG.TXT
ECHO "LastAccess"=hex:02,00,00,00>>                                                                                                   .\working\DUF_REG.TXT
ECHO "Folder"="C:\\WINDOWS\\msdownld.tmp|?:\\msdownld.tmp">>                                                                          .\working\DUF_REG.TXT
ECHO "FileList"="*.tmp">>                                                                                                             .\working\DUF_REG.TXT
ECHO "Priority"=hex:64,00,00,00>>                                                                                                     .\working\DUF_REG.TXT
ECHO "Flags"=hex:7c,00,00,00>>                                                                                                        .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content Indexer Cleaner]>>                   .\working\DUF_REG.TXT
ECHO @="{A9B48EAC-3ED8-11d2-8216-00C04FB687DA}">>                                                                                     .\working\DUF_REG.TXT
ECHO "PropertyBag"="{24400D16-5754-11d2-8218-00C04FB687DA}">>                                                                         .\working\DUF_REG.TXT
ECHO "FileList"="*.*">>                                                                                                               .\working\DUF_REG.TXT
ECHO "Folder"="?:\\Catalog.wci">>                                                                                                     .\working\DUF_REG.TXT
ECHO "Flags"=dword:00000141>>                                                                                                         .\working\DUF_REG.TXT
ECHO "Priority"=dword:0000012c>>                                                                                                      .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files]>>                  .\working\DUF_REG.TXT
ECHO @="{8369AB20-56C9-11D0-94E8-00AA0059CE02}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Display"="Downloaded Program Files">>                                                                                           .\working\DUF_REG.TXT
ECHO "Priority"=hex:64,00,00,00>>                                                                                                     .\working\DUF_REG.TXT
ECHO "AdvancedButtonText"="&View Files">>                                                                                             .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000000>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000000>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files]>>                      .\working\DUF_REG.TXT
ECHO @="{9B0EFD60-F7B0-11D0-BAEF-00C04FC308C9}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Display"="Temporary Internet Files">>                                                                                           .\working\DUF_REG.TXT
ECHO "AdvancedButtonText"="&View Files">>                                                                                             .\working\DUF_REG.TXT
ECHO "Priority"=dword:00000064>>                                                                                                      .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files]>>                         .\working\DUF_REG.TXT
ECHO @="{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}">>                                                                                     .\working\DUF_REG.TXT
ECHO "FileList"="*.dmp">>                                                                                                             .\working\DUF_REG.TXT
ECHO "Folder"=hex(2):25,00,57,00,49,00,4e,00,44,00,49,00,52,00,25,00,00,00>>                                                          .\working\DUF_REG.TXT
ECHO "LastAccess"=dword:0000001e>>                                                                                                    .\working\DUF_REG.TXT
ECHO "Display"="Debug Dump Files">>                                                                                                   .\working\DUF_REG.TXT
ECHO "Description"="Files created by Windows">>                                                                                       .\working\DUF_REG.TXT
ECHO "Flags"=dword:00000020>>                                                                                                         .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Microsoft Office Temp Files]>>               .\working\DUF_REG.TXT
ECHO @="{56197BB9-FBA0-4CFB-802B-129A9674D7C1}">>                                                                                     .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Microsoft_Event_Reporting_2.0_Temp_Files]>>  .\working\DUF_REG.TXT
ECHO @="{5A79987F-5D0A-425C-B70D-E49AD5B6BF23}">>                                                                                     .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Files]>>                             .\working\DUF_REG.TXT
ECHO @="{effc2928-37b1-11d2-a3c1-00c04fb1782a}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Priority"=dword:000000ca>>                                                                                                      .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files]>>                       .\working\DUF_REG.TXT
ECHO @="{8E6E6079-0CB7-11d2-8F10-0000F87ABD16}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Display"="Offline Web Pages">>                                                                                                  .\working\DUF_REG.TXT
ECHO "AdvancedButtonText"="&View Pages">>                                                                                             .\working\DUF_REG.TXT
ECHO "Priority"=dword:00000064>>                                                                                                      .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin]>>                               .\working\DUF_REG.TXT
ECHO @="{5ef4af3a-f726-11d0-b8a2-00c04fc309a4}">>                                                                                     .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Remote Desktop Cache Files]>>                .\working\DUF_REG.TXT
ECHO @="{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}">>                                                                                     .\working\DUF_REG.TXT
ECHO "FileList"="*.BMC">>                                                                                                             .\working\DUF_REG.TXT
ECHO "Flags"=dword:00000120>>                                                                                                         .\working\DUF_REG.TXT
ECHO "Display"="Temporary Remote Desktop files">>                                                                                     .\working\DUF_REG.TXT
ECHO "CSIDL"=dword:0000001c>>                                                                                                         .\working\DUF_REG.TXT
ECHO "Folder"="Microsoft\\Terminal Server Client\\Cache">>                                                                            .\working\DUF_REG.TXT
ECHO "LastAccess"=dword:00000007>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files]>>                           .\working\DUF_REG.TXT
ECHO @="{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}">>                                                                                     .\working\DUF_REG.TXT
ECHO "FileList"="setup*.log|setup*.old|setuplog.txt|winnt32.log">>                                                                    .\working\DUF_REG.TXT
ECHO "Folder"=hex(2):25,00,57,00,49,00,4e,00,44,00,49,00,52,00,25,00,00,00>>                                                          .\working\DUF_REG.TXT
ECHO "LastAccess"=dword:0000001e>>                                                                                                    .\working\DUF_REG.TXT
ECHO "Display"="Setup Log Files">>                                                                                                    .\working\DUF_REG.TXT
ECHO "Description"="Files created by Windows">>                                                                                       .\working\DUF_REG.TXT
ECHO "Flags"=dword:00000020>>                                                                                                         .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files]>>                           .\working\DUF_REG.TXT
ECHO @="{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}">>                                                                                     .\working\DUF_REG.TXT
ECHO "PropertyBag"="{60F6E465-4DEF-11d2-B2D9-00C04F8EEC8C}">>                                                                         .\working\DUF_REG.TXT
ECHO "FileList"="*.*">>                                                                                                               .\working\DUF_REG.TXT
ECHO "Folder"=hex(2):25,00,54,00,45,00,4d,00,50,00,25,00,00,00>>                                                                      .\working\DUF_REG.TXT
ECHO "Flags"=dword:0000005d>>                                                                                                         .\working\DUF_REG.TXT
ECHO "LastAccess"=dword:00000003>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Offline Files]>>                   .\working\DUF_REG.TXT
ECHO @="{750fdf0f-2a26-11d1-a3ea-080036587f03}">>                                                                                     .\working\DUF_REG.TXT
ECHO "Priority"=dword:000000c9>>                                                                                                      .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
ECHO.>>                                                                                                                               .\working\DUF_REG.TXT
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\WebClient and WebPublisher Cache]>>          .\working\DUF_REG.TXT
ECHO @="{E3BF1126-BA29-4850-AF33-5BDB654F4774}">>                                                                                     .\working\DUF_REG.TXT
ECHO "StateFlags"=dword:00000001>>                                                                                                    .\working\DUF_REG.TXT
ECHO "StateFlags1972"=dword:00000002>>                                                                                                .\working\DUF_REG.TXT
GOTO :EOF

:DELETE_WILDCARD_DIRECTORY
DIR "%~2" /S /B /AD>.\working\DUF_DIRS.TXT 2>&1
IF NOT EXIST .\working\DUF_DIRS.TXT GOTO :EOF
FINDSTR /I /C:"File Not Found" .\working\DUF_DIRS.TXT>NUL
IF "%ERRORLEVEL%" EQU "0" GOTO :EOF
CALL :LOG "1" "%~3"
IF EXIST .\working\DUF_DIRS.TXT FOR /F "tokens=*" %%a IN (.\working\DUF_DIRS.TXT) DO CALL :DELETE_DIRECTORY "2" "%%a"   "%~2" "%~3"
GOTO :EOF

:CLEAR_WILDCARD_DIRECTORY
DIR "%~2" /S /B /AD>.\working\DUF_DIRS.TXT 2>&1
IF NOT EXIST .\working\DUF_DIRS.TXT GOTO :EOF
FINDSTR /I /C:"File Not Found" .\working\DUF_DIRS.TXT>NUL
IF "%ERRORLEVEL%" EQU "0" GOTO :EOF
CALL :LOG "1" "%~3"
IF EXIST .\working\DUF_DIRS.TXT FOR /F "tokens=*" %%a IN (.\working\DUF_DIRS.TXT) DO CALL :CLEAR_DIRECTORY "2" "%%a"   "%~2" "%~3"
GOTO :EOF

:DELETE_FILES_AND_DIRECTORIES
REM  :DELETE_FILES "%~1" "%~2\*"
REM  :DELETE_DIRECTORY "%~1" "%~2"
GOTO :EOF

:CLEAR_DIRECTORY
IF EXIST "%~2" (
  CALL :LOG "1" "%~3"
  DIR "%~2" /S /B /AD>.\working\DUF_FILES.TXT
)
IF EXIST .\working\DUF_FILES.TXT FOR /F "tokens=*" %%a IN (.\working\DUF_FILES.TXT) DO CALL :DELETE_DIRECTORY "2" "%%a"   "%~2" "%~3"
IF EXIST .\working\DUF_FILES.TXT FOR /F "tokens=*" %%a IN (.\working\DUF_FILES.TXT) DO CALL :DELETE_FILES     "0" "%%a\*" "%~2" "%~3"
GOTO :EOF

:DELETE_DIRECTORY
IF "%~2" EQU "" GOTO :EOF
IF NOT EXIST "%~2" GOTO :EOF
CALL :START "%~1" "RD /S /Q" "%~2" "%~3"
GOTO :EOF

:DELETE_FILES
IF "%~2" EQU "" GOTO :EOF
CALL :START "%~1" "DEL /S /Q" "%~2" "%~3"
GOTO :EOF

:SERVICES
IF "%1" EQU "STOP"  SET DUF_SERVICE=Stopping
IF "%1" EQU "START" SET DUF_SERVICE=Starting
CALL :LOG "1" "%DUF_SERVICE% Automatic Updates and BITS services"
START /MIN /WAIT NET %~1 "Automatic Updates" /Y
START /MIN /WAIT NET %~1 "Background Intelligent Transfer Service" /Y
GOTO :EOF

:APPLICATIONS
IF "%1" EQU "STOP"  SET DUF_SERVICE=Stopping
IF "%1" EQU "START" SET DUF_SERVICE=Starting
CALL :LOG "1" "%DUF_SERVICE% file locking applications"
TASKKILL /F /IM dpupdchk.exe /T>NUL 2>&1
TASKKILL /F /IM iexplore.exe /T>NUL 2>&1
TASKKILL /F /IM Indexer.exe /T>NUL 2>&1
TASKKILL /F /IM iTunesHelper.exe /T>NUL 2>&1
TASKKILL /F /IM jusched.exe /T>NUL 2>&1
GOTO :EOF

:START
CALL :LOG "%~1" "%~4" "%~3"
START "%~4" %DUF_START% %ComSpec% %DUF_ComSpec% %~2 "%~3"
GOTO :EOF

:LOG
IF "%~1" EQU "2" ECHO   - %~3..
IF "%~1" EQU "1" ECHO * %~2..
GOTO :EOF

:DISPLAY_HEADER
ECHO.
ECHO %SCRIPT_NAME%
ECHO.===============================================================================
ECHO.
GOTO :EOF

:DISPLAY_FOOTER
ECHO.
ECHO.===============================================================================
ECHO.
GOTO :EOF

:END
ENDLOCAL

:EOF
